<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>~설문설문~</title>

<style type="text/css">
<!--
#survey_info {
	margin: 0 auto;
	width: 90%;
	background-color: #FFF;
}
#survey_info li {
	
	text-decoration: none;
}

#survey_info_title{
	font-size:13px;
	color:#FF9977;
	font-weight:bold;
}

#survey_info_contents{
	font-size:15px;
	color:#777777;
}

-->
</style>
<script type="text/javascript" src="./js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="./js/util.js"></script>
</head>
<body>
<?php
	require_once('db_connect.php');
	
	function getKeywords($survey_id) {
		global $conn;
		$keyword_list = array();
		$query = "select * from keyword_survey where survey_id = ".$survey_id;
		$kw_data = mysqli_query($conn, $query)
			or die("keyword_survey에서 survey id ".$row['id']." 로 가져오는 쿼리 실패");
		while ($kw_row = mysqli_fetch_array($kw_data)) {
			array_push($keyword_list, $kw_row['keyword']);
		}
		return $keyword_list;
	}
	
	$survey_id = $_GET['sid'];
	$keywords = '';
	$keyword_list = getKeywords($survey_id);
	foreach ($keyword_list as $keyword)
		$keywords .= $keyword.', ';
	
	$query = "select * from survey where id='$survey_id'";
	$data = mysqli_query($conn, $query)
		or die("$survey_id 로 survey 가져오는 쿼리 실패");
		
	if (mysqli_num_rows($data) <= 0)
		die("$survey_id 를 id로 가진 survey가 db 에 없음");
	
	$row = mysqli_fetch_array($data);
?>
	<ul id="survey_info">
		<font id='survey_info_contents'><h3><u><?php echo $row[title]; ?></u></h3></font></li>
		<li><font id='survey_info_title'>작성자 : </font><font id='survey_info_contents'><?php echo $row[member_id]; ?></font></li>
		<li><font id='survey_info_title'>조회수 : </font><font id='survey_info_contents'><?php echo $row[view_count]; ?></font></li>
		<li><font id='survey_info_title'>생성시간 : </font><font id='survey_info_contents'><?php echo $row[create_time]; ?></font></li>
		<li><font id='survey_info_title'>카테고리 : </font><font id='survey_info_contents'><?php echo $row[category]; ?></font></li>
		<li><font id='survey_info_title'>키워드 : </font><font id='survey_info_contents'><?php echo $keywords; ?></font></li>
		<li><font id='survey_info_title'>기간 : </font><font id='survey_info_contents'><?php echo $row[start_date].' ~ '.$row[end_date]; ?></font></li>
		<li><font id='survey_info_title'>시간대 : </font><font id='survey_info_contents'><?php echo $row[start_time].' 부터 ~ '.$row[end_time]; ?> 까지</font></li>
		<li><font id='survey_info_title'>참여가능인원 : </font><font id='survey_info_contents'><?php echo $row[max_capacity]; ?></font></li>
		<li><font id='survey_info_title'>유형 : </font><font id='survey_info_contents'><?php echo ($row[is_once] ? '반복형' : '1회형'); ?></font></li>
		<li><font id='survey_info_title'>인증필요 : </font><font id='survey_info_contents'><?php echo ($row[require_login] ? '예' : '아니오'); ?></font></li>
		<li><font id='survey_info_title'>중간결과보기 : </font><font id='survey_info_contents'><?php echo ($row[mid_result] ? '가능' : '불가'); ?></font></li>
		
		<li><font id='survey_info_title'>위치조건 : </font><font id='survey_info_contents'>
		<?php
		if($row[ap_id])
		{
			echo "[실내] ";
			$query = "select * from standard_ap where ap_id = '$row[ap_id]'";
			$result = mysqli_query($conn, $query);
			$rows = mysqli_fetch_array($result);
			echo $rows[locatename];
			echo "( $rows[mac] )<br>";
		}
		
		if($row[gps_id])
		{
			echo "[실외] ";
			$query = "select * from standard_gps where gps_id = '$row[gps_id]'";
			$result = mysqli_query($conn, $query);
			$rows = mysqli_fetch_array($result);
			echo $rows[locatename];
			echo "<br>( 위도 : $rows[latitude] / 경도 : $rows[longitude] / 반경 : $rows[radius] )";
		}
		
		if($row[ap_id] == '' && $rows[gps_id] == '')
		{
			echo "조건 없음<br>";
		}
		?></font></li>
		<li><font id='survey_info_title'>기본조건 : <br /></font><font id='survey_info_contents'>
		<?php 
			$query = "select * from basic_condition where survey_id='$survey_id'";
			$data = mysqli_query($conn, $query);
			if (mysqli_num_rows($data) <= 0)
				echo '없음';
			else {
				$first = true;
				while ($row = mysqli_fetch_array($data)) {
					if (!$first)
						$cond = 'OR ';
					else {
						$cond = '';
						$first = false;
					}
					if (!empty($row[age]))
						$cond .= "연령대: $row[age] 대 & ";
					if (!empty($row[edulevel])) {
						$cond .= "학력: ";
						switch ($row[edulevel]) {
							case 1: $cond .= '중졸 이하'; break;
							case 2: $cond .= '고졸'; break;
							case 3: $cond .= '초대졸'; break;
							case 4: $cond .= '대졸'; break;
							case 5: $cond .= '대학원졸 이상'; break;
						}
						$cond .= ' & ';
					}
					if ($row[gender] != 0)
						$cond .= "성별: ".($row[gender] == 1 ? "남자" : "여자")." & ";
					if (!empty($row[addr]))
						$cond .= "거주지: $row[addr] & ";
						
					$cond = preg_replace('/\s*&\s*$/', '', $cond);
					echo $cond.'<br />';
				}
			}
		?>
		</font></li>
	</ul>
</body>
</html>
